

'''
# 判断一个元素是不是在列表里面，这个方法效率低,需要用字典和集合更快
user_list = ['王宝强','Alex','Ab羽凡','贾乃亮','贾乃','1']
if 'Alex' in user_list:
    index = user_list.index('Alex')     # 获取这个的索引
    user_list.pop(index)        # 根据索引删除值
print(user_list)
'''

"""
# 敏感词替换
text = input('请输入文本内容：')
forbidden_list = ['欧美','日韩','草']
for item in forbidden_list:
    text = text.replace(item,'**')
print(text)
"""

# 删除列表元素
# remove('要删除的值')   删除这个值，如果值不存在会报错
# pop(1)    根据索引删除，单个值
# del list[1]   根据索引删除，区间值
user_list = [1,'ahha','sdsf']
del user_list[1]
print(user_list)


l1 = [1,23,4]
l1[4234:]=['sdsd','haha',123]   # 不会报错
l1[-1232:1]=['我也','不','知','道','会','不','会']
print(l1)
l2 = l1[5:1:-1]
print(l2)

# for i in range(5,1,-2):
#     print(i)
# for i in range(5,1,-1):
#     print(i)

# 列表的反转
user_list = [1,235,7,8,9,3,5,7]
new_list = user_list[::-1]
print(new_list)
print(user_list)
user_list.reverse()     # 源列表改变
print(user_list)

# 面试题：实现一个字符串的反转,字符串是不可变类型
data = '我是你大爷'
new_data = data[::-1]
print(data)
print(new_data)


'''
# 错误提示：千万不要一边循环一边删除，会出问题
user_list = ['刘德华','刘哈哈','宋小宝','刘颖','王立功','刘妮马']
for item in user_list:  # 循环顺序按列表索引来 0 1 2 3
    if item.startswith('刘'):
        user_list.remove(item)
print(user_list)    # ['刘哈哈', '宋小宝', '王立功']
'''

# 可以倒着处理
user_list = ['刘德华','刘哈哈','宋小宝','刘颖','王立功','刘妮马']
for index in range(len(user_list)-1,-1,-1):  # 循环顺序按列表索引来 0 1 2 3
    item = user_list[index]
    if item.startswith('刘'):
        user_list.remove(item)
print(user_list)    # ['宋小宝', '王立功']


# 字符串转列表
name= '我爱学习'
print(list(name))   # ['我', '爱', '学', '习']

'''
# extend()的内部就是for循环
li = ['wo','ai','xuexi']
st = 'loving'
for item in st:
    li.append(item)
print(li)
'''
li = ['wo','ai','xuexi']
li.extend('loving')
print(li)

'''
data_list = []
for num in range(0,50):
    if num ==0:
        continue
    data = num%3
    if data==0:
        data_list.append(num)
print(data_list)
'''
data_list = []
for num in range(0,50):
    if num ==0:
        continue
    data = num%3
    if data==0:
        data_list.insert(0,num)
print(data_list)